using System;
using System.Collections.Generic;
using ACS.Compiler.Synthes;
using ACS.Compiler.Tables;
using ACS.Compiler.Tree.Interfaces;

namespace ACS.Compiler.Tree.Impl
{
    public class Block : Statement, ICodeItem
    {
        private List<Statement> _statements = new List<Statement>();

        public List<Statement> Stmts
        {
            get { return _statements; }
        }

        public override void MatchStatement(Statement statement)
        {
            _statements.Add(statement);
        }

        public override void MatchCall(Call call)
        {
            _statements.Add(call);
        }

        public override void MatchBlock(Block block)
        {
            _statements.Add(block);
        }

        public override Statements StatementType
        {
            get { return Statements.Block; }
        }

        public override void Resolve(string ns, DataTable localData)
        {
            foreach (Statement statement in _statements)
            {
                statement.Resolve(ns, localData);                
            }
        }

        public override void Format()
        {
            Formatter.Current.Incr();
            Formatter.Current.Format("{");
            foreach (Statement statement in _statements)
            {
                statement.Format();
            }
            Formatter.Current.Decr();
            Formatter.Current.Format("\n}");
        }
    }
}
